// composables 存放公共的函数，即业务逻辑
import { ref, computed } from "vue"

export function useFilteredTodos(todos) {
  const filter = ref('all')
  const filteredTodos = computed(() => {
    switch (filter.value) {
      case "done":
        return todos.value.filter((todo) => todo.completed)
      case "todo":
        return todos.value.filter((todo) => !todo.completed)
      default:
        return todos.value
    }
  })

  return {
    filter,
    filteredTodos
  }
}